package com.example.demo.controller;

import com.example.demo.model.entity.ApplyEntity;
import com.example.demo.model.param.ApplyParam;
import com.example.demo.model.vo.ResponseVo;
import com.example.demo.service.ApplyService;
import com.example.demo.untils.BuildResponseUtils;
import com.example.demo.untils.PageBean;
import com.example.demo.untils.PageVoUtils;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ApplyController {

    @Autowired
    private ApplyService applyService;


    @PostMapping("/addApply")
    public ResponseVo<?> addApply(@RequestBody ApplyEntity applyEntity){
        return applyService.save(applyEntity) ? BuildResponseUtils.success():BuildResponseUtils.error();
    }


    @PostMapping("/listApply")
    public ResponseVo<?> listApply(@RequestBody ApplyParam applyParam){
        PageInfo pageInfo = applyService.selectApplierList(applyParam);
        PageBean pageBean = PageVoUtils.convertTopageVo(pageInfo);
        return BuildResponseUtils.buildResponse(pageBean);
    }


    @GetMapping("/deleteApply")
    public ResponseVo<?> deleteApply(@RequestParam("id") Integer id){
        return applyService.removeById(id)? BuildResponseUtils.success():BuildResponseUtils.error();
    }



    @PostMapping("/updateApply")
    public ResponseVo<?> updateApply(@RequestBody ApplyEntity applyEntity){
        return applyService.updateById(applyEntity) ? BuildResponseUtils.success():BuildResponseUtils.error();
    }
}
